package com.xgc.book.bookserver.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xgc.book.bookserver.bean.BookBean;
import com.xgc.book.bookserver.bean.BookCatalogBean;
import com.xgc.book.bookserver.bean.BookCommentBean;
import com.xgc.book.bookserver.bean.CategoryBean;
import com.xgc.book.bookserver.service.*;
import com.xgc.book.bookserver.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassNameApiBookController
 * @Author:王润之
 * @Description
 * @DateTime2023/11/27 13:53
 **/
@RestController
@RequestMapping(value = {"/api/v1/book", "/wx/v1/book"})
public class ApiBookController {
    @Autowired
    private BookService bookService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private BookCategoryService bookCategoryService;
    @Autowired
    private BookCatalogService bookCatalogService;
    @Autowired
    private BookCommentService bookCommentService;

    @GetMapping("/hot/list")
    public ResultJson hotList() {
        return bookService.hotList();
    }

    @GetMapping("/category/list")
    public ResultJson categoryList() {
        List<CategoryBean> categoryList = categoryService.list(new QueryWrapper<CategoryBean>().eq("status", 1));
        return ResultJson.ok(categoryList);
    }

    @GetMapping("/page")
    public ResultJson page(int page) {
        BookBean bookBean = new BookBean();
        bookBean.setStatus(1);
        return bookService.getPage(page, 5, bookBean);
    }

    @GetMapping("/category/page")
    public ResultJson categoryPage(int page, int limit, int categoryId) {
        return bookCategoryService.getBookPageByCategoryId(page, limit, categoryId);
    }

    @GetMapping("/info/{bookId}")
    public ResultJson info(@PathVariable int bookId) {
        return ResultJson.ok(bookService.getById(bookId));
    }

    @GetMapping("/catalog/page")
    public ResultJson catalogPage(int page, int limit, int bookId) {
        BookCatalogBean bookCatalogBean = new BookCatalogBean();
        bookCatalogBean.setBookId(bookId);
        bookCatalogBean.setStatus(1);
        return bookCatalogService.getPage(page, limit, bookCatalogBean);
    }

    @GetMapping("/comment/page")
    public ResultJson commentPage(int page, int limit, int bookId) {
        BookCommentBean bookCommentBean = new BookCommentBean();
        bookCommentBean.setBookId(bookId);
        bookCommentBean.setStatus(1);
        return bookCommentService.getPage(page, limit, bookCommentBean);
    }
}
